{{define "content"}}

    {{if .UserList}}
    <h3>{{.Title}}</h3>

    <table class="table table-striped table-dark">
        <thead>
        <tr>
            <th scope="col">#</th>
            <th scope="col">Name</th>
            <th scope="col">E-mail</th>
            <th scope="col">E-mails</th>
            <th scope="col">Files</th>
        </tr>
        </thead>
        <tbody>
        {{range $i, $u := .UserList}}
        <tr>
            
            <td scope="row">{{$i}}</td>
            <td>{{$u.DisplayName}}</td>
            <td>{{$u.Mail}}</td>
            <td><a class="btn btn-success btn-sm" href="/live/user/{{.Mail}}/emails">Search E-mails</a> <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-email="{{$u.Mail}}" data-target="#sendMailModal">Send E-mail</button></td>
            <td>
                <a class="btn btn-success btn-sm" href="/live/user/{{.Mail}}/files">Search Files</a>
                <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-email="{{.Mail}}" data-target="#fileModal">View Files</button>
            </td>
        </tr>
        {{end}}
        </tbody>
    </table>
        {{else}}
        <div class="alert alert-warning show" role="alert">
           Nothing here :/ - You are a bad pirate !!!!
        </div>
        {{end}}


    <div class="modal fade" id="emailModal" tabindex="-1" role="dialog" aria-labelledby="emailModal" aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="emailModalTitle">E-mails</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                        Diz iz da body
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-success" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="fileModal" tabindex="-1" role="dialog" aria-labelledby="fileModal" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="fileModalTitle">Files</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    Diz iz da body
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-success" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

  <!-- Modal for Email Sending -->
  <div class="modal fade"   id="sendMailModal" tabindex="-1" role="dialog" aria-labelledby="sendMailModal" aria-hidden="true">
    <div class="modal-dialog modal-lg " role="document">
        <div class="modal-content">
            <div class="modal-header">
            <div class="modal-body">
                <form method="POST" action="/" id="sendEmailForm" enctype="multipart/form-data">
                    <div class="form-group">
                      <label for="emailtarget">Email address</label>
                      <input type="email" class="form-control" name="emailtarget" id="emailtarget" aria-describedby="emailHelp" placeholder="Target">
                    </div>
                    <div class="form-group">
                        <label for="contentType">Content Type:</label>
                            <select class="form-control-sm" name="contentType" id="contentType">
                                <option value="HTML">text/html</option>
                                <option value="Text">text</option>
                            </select>
                    </div>

                   
                    <div class="form-group">
                        <label for="subject">Subject</label>
                        <input class="form-control" name="subject" id="subject" aria-describedby="emailHelp" placeholder="Subject">
                        </div>
                    <div class="form-group">
                        <label for="message">Message Details</label>
                        <textarea class="form-control rounded-0" name="message" id="message" rows="10"></textarea>
                    </div>

                    <div class="form-group">
                        <label for="attachment">Attachment</label><br>
                        <input type="file" name="attachment" id="attachment">
                        
                      </div>
                      
                    <button type="submit" class="btn btn-primary">Send</button>
                  </form>

                  
            </div>
        </div>
    </div>
</div>


    <script>
        $('#emailModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var email = button.data('email');
            var modal = $(this);
            modal.find('.modal-body').text(email);
        });

        $('#fileModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var email = button.data('email');
            var modal = $(this);
            $.get( "/user/"+email+"/files", function( data ) {
                modal.find('.modal-body').html(data);
            });
        });

        $('#sendMailModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var email = button.data('email');
            var modal = $(this);
            document.getElementById("sendEmailForm").action = "/live/user/"+ email +"/send/email";
        });

    </script>


{{end}}